package com.gusha.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

import com.gusha.model.SysMenu;
import com.gusha.model.SysRole;
import com.gusha.model.SysRoleMenu;


/**
 * @Created：2018-10-26 15:18:16
 * @Author LightSound的代码生成器
 * @Description:SysRoleMenuDao接口
 */
@Repository
public interface SysRoleMenuDao extends JpaRepository<SysRoleMenu,BigInteger>,JpaSpecificationExecutor<SysRoleMenu> {

	@Query(value="select rm.menu from SysRoleMenu rm where rm.role = ?1 and rm.menu.menuLevel=1 order by rm.menu.sort desc")
	List<SysMenu> getMenuByRole(SysRole role);

	@Query(value="select rm.menu from SysRoleMenu rm where rm.role = ?1 and rm.menu.menuLevel=2 and rm.menu.parentId = ?2 order by rm.menu.sort desc")
	List<SysMenu> getSecondMenuByRoleAndMenu(SysRole role, BigInteger id);

	List<SysRoleMenu> findAllByMenu_Id(BigInteger id);

	void deleteAllByRole(SysRole sysRole);

	@Query(value="select rm.menu.id from SysRoleMenu rm where rm.role = ?1")
	List<BigInteger> findAllMenuByRole(SysRole sysRole);


}
